/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#ifndef WIDGETREGISTRY_HPP
#define WIDGETREGISTRY_HPP

#include <boost/unordered_map.hpp>
#include <string>

#include "ForwardDecls.hpp"
#include "HelpDefs.hpp"

namespace spelprog2 {
namespace gui {

class WidgetRegistry {
    HIDE_EVIL_CONSTRUCTORS(WidgetRegistry);

    typedef boost::unordered_map<std::string, QuickGUI::Widget *> WidgetMap;
    WidgetMap widgets_;
public:
    WidgetRegistry() : widgets_() { }
    virtual ~WidgetRegistry() { }

    void add(const std::string & key, QuickGUI::Widget * w);
    void add(const std::string & key, QuickGUI::Widget & w) { add(key, &w); }

    QuickGUI::Widget & get(const std::string & key);
#ifndef _NDEBUG
    template <typename W> W & get(const std::string & key) { return dynamic_cast<W &>(get(key)); }
#else
    template <typename W> W & get(const std::string & key) { return static_cast<W &>(get(key)); }
#endif //_NDEBUG

    void destroy(const std::string & key);
};

}; //gui
}; //spelprog2

#endif //WIDGETREGISTRY_HPP
